home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / cbm / 4678 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!gate.demon.co.uk
  2. From: Jason <tmr@cosine.demon.co.uk>
  3. Newsgroups: comp.sys.cbm
  4. Subject: Re: Scanning strings under BASIC, avoiding INPUT "?"
  5. Date: Wed, 27 Mar 96 22:58:59 GMT
  6. Organization: Cosine Systems
  7. Message-ID: <9603272258.AA0014u@cosine.demon.co.uk>
  8. References: <4jc9kt$h3p@news.rrz.uni-koeln.de>
  9. X-NNTP-Posting-Host: gate.demon.co.uk
  10. X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
  11. X-Mail2News-Path: relay-1.mail.demon.net!gate.demon.co.uk
  12.  
  13. Joerg Bleimann (a2233495@rrz.Uni-Koeln.DE) wrote:
  14.  
  15. : I have got a problem with COMMODORE BASIC 2.0: I started programming a
  16. : text adventure on the C 64 and do not know how to make the computer
  17. : recognize the latter part of a bipartite command string (for example
  18. : "TAKE BOTTLE"). How can I search the whole string for empties (" ") to
  19. : redefine the part right from the empty as a new string?
  20.  
  21. You need to use the sexy little MID$ command.  Eg:
  22.  
  23. 10 A$="EAT GOLDFISH"
  24. 20 B$=MID$(A$,5,8)
  25. 30 PRINT B$
  26.  
  27. Will put just the word GOLDFISH on your screen.
  28.  
  29. The first number specifies where to start from in A$ and the second says
  30. how much to take.  You can, therefore use it to scan one character at a
  31. time through the string using MID$(A$,T,1) with T as a counter to find the
  32. space and then fracture the two halves off thus:
  33.  
  34. 10 INPUT A$                 ;Get a command
  35. 20 T=1                      ;Reset variable T to scan the string
  36. 30 L=LEN(A$)                ;Get length of the command string
  37. 40 IFMID$(A$,T,1)=" "THEN70 ;Read character and compare with space
  38. 50 T=T+1                    ;Add one to counter
  39. 60 IFT<=LTHEN40             ;See if counter has passed the end of the string
  40. 70 C$=MID$(A$,1,T-1)        ;C$=COMMAND$ (Get, Go, Etc.)
  41. 80 O$=MID$(A$,T+1,L-T)      ;O$=OBJECT$  (Banana, North, Etc.)
  42. 90 PRINTC$:PRINTO$          ;Show the result of this test
  43.  
  44. Since this is an example there is no error trapping for things like
  45. incorrect inputs, shifted spaces or having more than two words a line but
  46. it should be easy to add that to it!  Hioe that helps!!
  47.  
  48. Jason  =-)
  49.